﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.IO;
using Magnum.FileSystem;

namespace WebAPI.Controllers
{
    public class download : ApiController
    {
        //接受下载
        public HttpResponseMessage Get(string Filename)
        {
            var path = System.Web.HttpContext.Current.Server.MapPath($"~/Flie/lmg/{Filename}");
            // var orighinName = "class1.cs";
            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
            var stream = new FileStream(path, FileMode.Open);
            result.Content = new StreamContent(stream);
            result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");  
            //FileName = orighinName;
            result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
            result.Content.Headers.ContentLength = stream.Length;
            return result;
        }

    }
}
